/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-01-04 14:18:24
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-05-04 14:38:49
 * @FilePath: \cxl-admin\src\apis\finance\pay.ts
 */
import axios from '../../axios/index'

//退款原因
export const refundOptions: any[] = [
    { value: '1', label: '购买错误' },
    { value: '2', label: '报告数据不准' },
    { value: '3', label: '不合适' },
    { value: '4', label: '其它' }
]

interface pageInterface {
    current: number //当前页
    size: number //每页数量
    companyId?: string //企业id
    optStatus?: number //操作状态（1.正常；2.退款中；3.已退款）
    phone?: string //手机号
    storeDateEnd?: string //储值结束时间
    storeDateStart?: string //储值开始时间
}

/**
 * 获取企业充值分页
 * @param params
 * @returns
 */

export const payPage = (params: pageInterface) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/pageList',
        params
    })
}

/**
 * 计算退款金额
 * @param id
 * @returns
 */
export const calculateRefundAmound = (id: string) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/calculate-refund-amount',
        params: { id }
    })
}

/**
 * 根据筛选导出列表
 * @param params
 * @returns
 */
export const exportList = (params?: Omit<pageInterface, 'current' | 'size'>) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/export-list',
        params
    })
}

/**
 * 获取公司钱包余额
 * @param companyId
 * @returns
 */
export const getCompanyBalanceById = (companyId: string) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/query-remain-amount',
        params: { companyId }
    })
}

interface refundInterface {
    refundReason: number //退款理由（1.购买错误；2.报告数据不准；3.不合适；4.其他）
    bankAccount?: string //银行账号
    branches?: string //开户网点
    brank?: string //收款银行
    companyId?: string //企业id
    description?: string //备注说明
    id?: string
    receiverName?: string //收款人姓名
}

/**
 * 退款
 * @param params
 * @returns
 */
export const refund = (data: refundInterface) => {
    return axios({
        method: 'post',
        url: '/api/mall/company/store/refund',
        data
    })
}

/**
 * 退款详情
 * @param storeRefundId
 * @returns
 */
export const getRefundDetailed = (storeRefundId: string) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/refund-detail',
        params: { storeRefundId }
    })
}

interface refundCertificateInterface {
    certificatePath?: string //退款凭证
    companyId?: string //企业ID
    id?: string //id
    storeRefundId?: string //退款ID
}

/**
 * 保存退款凭证
 * @param certificatePath?: string //退款凭证
 * @param companyId?: string //企业ID
 * @param id?: string //id
 * @param storeRefundId?: string //退款ID
 * @returns
 */
export const saveRefundCertificate = (data: refundCertificateInterface) => {
    return axios({
        method: 'post',
        url: '/api/mall/company/store/save-refund-certificate',
        data
    })
}

/**
 * 通过银行卡号获取开户行
 * @param card
 * @returns
 */
export const getBank = (card: string) => {
    return axios({
        method: 'get',
        url: `https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=${card}&cardBinCheck=true`
    })
}

interface PageParams {
    current: number
    size: number
    companyId: string
}

/**
 * 消费明细
 * @param params
 * @returns
 */
export const consumeDetailedPage = (params: PageParams) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/detail/report-order-list',
        params
    })
}

/**
 * 充值明细
 * @param params
 * @returns
 */
export const payDetailedPage = (params: PageParams) => {
    return axios({
        method: 'get',
        url: '/api/mall/company/store/detail/store-order-list',
        params
    })
}
